package com.mifengkong.cygtools.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mifengkong.cygtools.R;


/**
 * Created by jiangyongxing on 2017/5/24.
 * 描述：
 */

public class LoadingDialog extends Dialog {


    public LoadingDialog(Context context) {
        super(context);
    }

    public LoadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {

        private Activity activity;
        private LoadingDialog mDialog;
        private TextView mLoadingTv;
        private String mLoadingTip;
//        private AnimationDrawable mAnimationDrawable;


        public Builder(Activity activity) {
            this.activity = activity;
        }

        public Builder setMessage(String loadingMassage) {
            this.mLoadingTip = loadingMassage;
            return this;
        }

        /**
         * Create the custom dialog
         */
        public LoadingDialog create() {
            mDialog = new LoadingDialog(activity, R.style.dialog_http_progress);
            mDialog.setContentView(R.layout.dialog_loading);

            ImageView loadingView = mDialog.findViewById(R.id.pd_loading);
            mLoadingTv = mDialog.findViewById(R.id.pd_message);
//            mAnimationDrawable = (AnimationDrawable) activity.getResources().getDrawable(
//                    R.drawable.loading_anim);
//            loadingView.setBackground(mAnimationDrawable);
            if (!TextUtils.isEmpty(mLoadingTip)) {
                mLoadingTv.setVisibility(View.VISIBLE);
                mLoadingTv.setText(mLoadingTip);
            }
//            mDialog.setOnDismissListener(new OnDismissListener() {
//                @Override
//                public void onDismiss(DialogInterface dialog) {
//                    if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
//                        mAnimationDrawable.stop();
//                    }
//                }
//            });
//            mAnimationDrawable.start();
            return mDialog;
        }
    }

}